﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
using MS.Internal.Mita.Foundation;

namespace UIAStudio
{
    public class PropertyListWorkItem : WorkItem
    {
        PropertiesSheet _propertyView;
        UIObject _uiItem;

        public PropertyListWorkItem(WorkQueue queue, PropertiesSheet propertyView, UIObject item)
            : base(queue)
        {
            _propertyView = propertyView;
            _uiItem = item;
        }

        public override void Execute()
        {
            CustomClass myProperties = new CustomClass();

            List<UIProperty> properties = new List<UIProperty>();
            ThreadStart ts = delegate
            {
                foreach (UIProperty p in _uiItem.SupportedProperties)
                {
                    object uiProp = _uiItem.GetProperty(p);
                    if (uiProp != null)
                    {
                        CustomProperty myProp = new CustomProperty(p.Name, _uiItem.GetProperty(p).ToString(), true, true);
                        myProperties.Add(myProp);
                    }
                }
                _propertyView.SelectedObject = myProperties;
            };
            

            
            _propertyView.Invoke(ts);
        }
    }
}
